<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>食尚外卖 - 用户注册</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
        }

        body {
            background: linear-gradient(135deg, #f5f7fa 0%, #e4edf5 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }

        .container {
            display: flex;
            max-width: 1000px;
            width: 100%;
            background: white;
            border-radius: 20px;
            overflow: hidden;
            box-shadow: 0 15px 40px rgba(0, 0, 0, 0.12);
        }

        .banner {
            flex: 1;
            background: linear-gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)),
            url('https://images.unsplash.com/photo-1504674900247-0877df9cc836?ixlib=rb-4.0.3&auto=format&fit=crop&w=800&q=80');
            background-size: cover;
            background-position: center;
            color: white;
            padding: 40px;
            display: flex;
            flex-direction: column;
            justify-content: center;
        }

        .banner h2 {
            font-size: 2.5rem;
            margin-bottom: 20px;
            position: relative;
        }

        .banner h2:after {
            content: '';
            position: absolute;
            bottom: -10px;
            left: 0;
            width: 80px;
            height: 4px;
            background: #ff6b35;
            border-radius: 2px;
        }

        .banner p {
            font-size: 1.1rem;
            line-height: 1.6;
            opacity: 0.9;
            margin: 10px 0;
        }

        .features {
            margin-top: 30px;
        }

        .feature {
            display: flex;
            align-items: center;
            margin-bottom: 15px;
        }

        .feature i {
            color: #ff6b35;
            font-size: 1.2rem;
            margin-right: 15px;
        }

        .register-form {
            flex: 1;
            padding: 50px 40px;
        }

        .logo {
            display: flex;
            align-items: center;
            margin-bottom: 30px;
        }

        .logo-icon {
            background: #ff6b35;
            color: white;
            width: 50px;
            height: 50px;
            border-radius: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 24px;
            margin-right: 15px;
        }

        .logo-text {
            font-size: 1.8rem;
            font-weight: 700;
            color: #333;
        }

        .logo-text span {
            color: #ff6b35;
        }

        .form-header {
            margin-bottom: 30px;
        }

        .form-header h1 {
            font-size: 2.2rem;
            color: #333;
            margin-bottom: 10px;
        }

        .form-header p {
            color: #777;
            font-size: 1rem;
        }

        .form-group {
            margin-bottom: 20px;
        }

        label {
            display: block;
            margin-bottom: 8px;
            color: #555;
            font-weight: 500;
            font-size: 0.95rem;
        }

        .input-with-icon {
            position: relative;
        }

        .input-with-icon i {
            position: absolute;
            left: 15px;
            top: 50%;
            transform: translateY(-50%);
            color: #777;
        }

        input, select {
            width: 100%;
            padding: 15px 15px 15px 45px;
            border: 2px solid #e0e0e0;
            border-radius: 12px;
            font-size: 1rem;
            transition: all 0.3s;
        }

        input:focus, select:focus {
            border-color: #ff6b35;
            outline: none;
            box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.2);
        }

        .half-width {
            display: flex;
            gap: 15px;
        }

        .half-width .form-group {
            flex: 1;
        }

        .password-toggle {
            position: absolute;
            right: 15px;
            top: 50%;
            transform: translateY(-50%);
            cursor: pointer;
            color: #777;
        }

        .btn-submit {
            background: #ff6b35;
            color: white;
            border: none;
            padding: 16px;
            width: 100%;
            border-radius: 12px;
            font-size: 1.1rem;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s;
            margin-top: 10px;
            box-shadow: 0 4px 15px rgba(255, 107, 53, 0.3);
        }

        .btn-submit:hover {
            background: #e55a2b;
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(255, 107, 53, 0.4);
        }

        .login-link {
            text-align: center;
            margin-top: 25px;
            color: #777;
        }

        .login-link a {
            color: #ff6b35;
            text-decoration: none;
            font-weight: 600;
        }

        .login-link a:hover {
            text-decoration: underline;
        }

        @media (max-width: 768px) {
            .container {
                flex-direction: column;
            }

            .banner {
                padding: 30px 20px;
            }

            .register-form {
                padding: 40px 25px;
            }

            .half-width {
                flex-direction: column;
                gap: 0;
            }
        }
    </style>
</head>
<body>
<div class="container">
    <div class="banner">
        <h2>加入食尚外卖</h2>
        <p>注册成为会员，享受专属优惠和快速配送服务</p>
        <p>新用户注册即可获得30元优惠券</p>

        <div class="features">
            <div class="feature">
                <i class="fas fa-bolt"></i>
                <p>闪电配送，30分钟必达</p>
            </div>
            <div class="feature">
                <i class="fas fa-tag"></i>
                <p>每日特惠，超值套餐</p>
            </div>
            <div class="feature">
                <i class="fas fa-shield-alt"></i>
                <p>食品安全保障，放心享用</p>
            </div>
            <div class="feature">
                <i class="fas fa-percent"></i>
                <p>会员专享折扣与特权</p>
            </div>
        </div>
    </div>

    <div class="register-form">
        <div class="logo">
            <div class="logo-icon">
                <i class="fas fa-utensils"></i>
            </div>
            <div class="logo-text">食尚<span>外卖</span></div>
        </div>

        <div class="form-header">
            <h1>创建您的账户</h1>
            <p>请填写以下信息完成注册</p>
        </div>

        <form id="registrationForm">
            <div class="form-group">
                <label for="username">用户名</label>
                <div class="input-with-icon">
                    <i class="fas fa-user"></i>
                    <input type="text" id="username" name="username" placeholder="设置您的登录用户名" required>
                </div>
            </div>

            <div class="form-group">
                <label for="password">密码</label>
                <div class="input-with-icon">
                    <i class="fas fa-lock"></i>
                    <input type="password" id="password" name="password" placeholder="设置您的登录密码" required>
                    <i class="fas fa-eye password-toggle" id="togglePassword"></i>
                </div>
            </div>

            <div class="form-group">
                <label for="nickname">姓名</label>
                <div class="input-with-icon">
                    <i class="fas fa-signature"></i>
                    <input type="text" id="nickname" name="nickname" placeholder="请输入您的真实姓名" required>
                </div>
            </div>

            <div class="half-width">
                <div class="form-group">
                    <label for="gender">性别</label>
                    <div class="input-with-icon">
                        <i class="fas fa-venus-mars"></i>
                        <select id="gender" name="gender" required>
                            <option value="" disabled selected>请选择性别</option>
                            <option value="男">男</option>
                            <option value="女">女</option>
                        </select>
                    </div>
                </div>

                <div class="form-group">
                    <label for="telephone">手机号码</label>
                    <div class="input-with-icon">
                        <i class="fas fa-mobile-alt"></i>
                        <input type="tel" id="telephone" name="telephone" placeholder="请输入您的手机号码" required>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label for="address">配送地址</label>
                <div class="input-with-icon">
                    <i class="fas fa-map-marker-alt"></i>
                    <input type="text" id="address" name="address" placeholder="请输入您的详细地址" required>
                </div>
            </div>

            <button type="submit" class="btn-submit">立即注册</button>
        </form>

        <div class="login-link">
            <p>已有账户？<a href="http://localhost:8030/login.html">立即登录</a>
        </div>
    </div>
</div>

<script>
    // 密码可见性切换
    const togglePassword = document.querySelector('#togglePassword');
    const password = document.querySelector('#password');

    togglePassword.addEventListener('click', function() {
        const type = password.getAttribute('type') === 'password' ? 'text' : 'password';
        password.setAttribute('type', type);
        this.classList.toggle('fa-eye');
        this.classList.toggle('fa-eye-slash');
    });

    // 表单提交处理
    const form = document.getElementById('registrationForm');
    form.addEventListener('submit', function(e) {
        e.preventDefault();

        // 获取表单值
        const formData = {
            username: document.getElementById('username').value,
            password: document.getElementById('password').value,
            nickname: document.getElementById('nickname').value,
            gender: document.getElementById('gender').value,
            telephone: document.getElementById('telephone').value,
            address: document.getElementById('address').value
        };

        // 简单验证
        if (!formData.username || !formData.password || !formData.nickname ||
            !formData.gender || !formData.telephone || !formData.address) {
            alert('请填写所有必填字段！');
            return;
        }

        // 手机号验证
        const phoneRegex = /^1[3-9]\d{9}$/;
        if (!phoneRegex.test(formData.telephone)) {
            alert('请输入有效的手机号码！');
            return;
        }

        // 发送POST请求到后端
        fetch('http://localhost:8050/register', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            body: `username=${encodeURIComponent(formData.username)}&password=${encodeURIComponent(formData.password)}&nickname=${encodeURIComponent(formData.nickname)}&gender=${encodeURIComponent(formData.gender)}&telephone=${encodeURIComponent(formData.telephone)}&address=${encodeURIComponent(formData.address)}`
        })
        .then(response => response.text())
        .then(msg => {
            if (msg === '注册成功') {
                alert('注册成功！欢迎加入食尚外卖');
                window.location.href = 'login.html'; // 跳转到登录页
            } else {
                alert(msg); // 比如“用户名已存在”
            }
        })
        .catch(error => {
            alert('注册失败，请稍后再试！');
            console.error(error);
        });
    });
</script>
</body>
</html>